#pragma once
#include <stdio.h>
#include <string>
#include "Package.h"
#include "User.h"
#include <iostream>
#include <queue>
#include "semafor2.h"

using namespace std;

class User {
	static int counter;

	unsigned int id;
	const unsigned int socket; /* gniazdo do kt���rego jest przywi���zany klient */
	string login;

	unsigned int gameId;	 /* gra w kt���rej aktualnie jest gracz, brak gry = 0 */
	unsigned int scores;	 /* punkty gracza */
	bool drawer; 			/* czy gracz jest graczem rysuj���cym */
	int semid;
	int semid2;

	queue<Package *> buffer; //bufor na wiadomo���ci ktore wrzuca server do wys���ania dla uzytkownika

public:

	User(int socket_) :	id(++counter), socket(socket_),  drawer(false), scores(0), gameId(0) {	}
	User(const User& user) : id(user.id), socket(user.socket), drawer(user.drawer), scores(user.scores), semid(user.semid), buffer(user.buffer), gameId(user.gameId),  login(user.login) {}

	~User();

	User operator=(const User & user){return User(this->socket);}

	// tworzy i inicjalizuje semafory dla buffer
	void createSem();

	// wklada wiadomosc na kolejke usera buffer
	void sendToClient(int code) ;
	void sendToClient(int code, string msg);
	void sendToClient(int code, char *tab);
	void sendToClient(int code, int val);

	// zdejmuje z kolejki buffer
	Package * messageFromBuffer();

	void updateScores(int a) {		scores = scores + a;}
	bool inAnyGame() {		return gameId != 0;}

	void setLogin(string login_) {		login = login_;	}
	void setGameId(unsigned int gameId_) {		gameId = gameId_;	}
	void setDrawer(bool drawer_) {		drawer = drawer_;	}
	void setScores(int scores_) {		scores = scores_;	}
	void setId(int id_) {		id = id_;	}
	int getId() {		return id;	}
	string getLogin(){	return login;	}
	int getGameId(){		return gameId;	}
	int getScores(){		return scores;	}
	bool getDrawer(){		return drawer;	}
	static int getCounter(){return counter;	}
	int getSocket(){		return socket;	}
};
